home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VELENG10.ZIP / PLAYGAME.C < prev    next >
C/C++ Source or Header  |  1997-07-27  |  3KB  |  109 lines

  1. // ****************************************************************************
  2. // *                                                                          *
  3. // *                      Velena Source Code V1.0                             *
  4. // *                   Written by Giuliano Bertoletti                         *
  5. // *       Based on the knowledged approach of Louis Victor Allis             *
  6. // *   Copyright (C) 1996-97 by Giuliano Bertoletti & GBE 32241 Software PR   *
  7. // *                                                                          *
  8. // ****************************************************************************
  9.  
  10. // Portable engine version.
  11. // read the README file for further informations.
  12.  
  13. // ==========================================================================
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. #include <malloc.h>
  20.  
  21. #include "connect4.h"
  22. #include "pnsearch.h"
  23. #include "proto.h"
  24.  
  25. #define LINEX 46
  26. #define LINEY 21
  27.  
  28. char *endg[]={"Draw !","Yellow wins","Red wins"};
  29. short computer_play=BLACK,autoplay=NO;
  30.  
  31. void takeback(struct board *board,short howmany)
  32.     {
  33.     board->oracle[0]=0;
  34.     board->oracle[1]=0;
  35.  
  36.     while(board->filled>0 && howmany>0)
  37.         {
  38.         undomove(board,board->moves[board->filled-1]);
  39.         howmany--;
  40.         }
  41.     }
  42.  
  43. short parse_input_string(char *str,struct board *board)
  44.         {
  45.         short cnt=0,move;
  46.         char *p;
  47.  
  48.         p=str;
  49.  
  50.         board->cpu = 3;
  51.  
  52.         switch(*p)
  53.                 {
  54.                 case 'a':
  55.                    board->white_lev = 1;
  56.                    board->black_lev = 1;
  57.                    break;
  58.  
  59.                 case 'b':
  60.                    board->white_lev = 2;
  61.                    board->black_lev = 2;
  62.                    break;
  63.  
  64.                 case 'c':
  65.                    board->white_lev = 3;
  66.                    board->black_lev = 3;
  67.                    break;
  68.  
  69.                 default:
  70.                    return -1;
  71.                 }
  72.  
  73.         p++;
  74.  
  75.         while(p[cnt]!='0')
  76.            {
  77.            move=(short)(p[cnt]-'1');
  78.            if(move<0 || move>6) return -1;
  79.  
  80.            if(board->stack[move]<BOARDY) makemove(board,move);
  81.            else return -2;
  82.  
  83.            if(cnt>=42 || endgame(board)!=0) return -2;
  84.            cnt++;
  85.            }
  86.  
  87.         return 1;
  88.         }
  89.  
  90.  
  91.  
  92. short playgame(char *input_str,struct board *board)
  93.     {
  94.     int flag;
  95.  
  96.     board->oracle[0]=0;
  97.     board->oracle[1]=0;
  98.  
  99.         initboard(board);
  100.         flag=parse_input_string(input_str,board);
  101.     if(flag<=0) return flag;
  102.  
  103.         return ia_compute_move(board)+1;
  104.         }
  105.  
  106.  
  107.  
  108.  
  109.